package com.yz.hw_student.system.controller;


import com.yz.hw_student.system.entity.SysRole;
import com.yz.hw_student.system.service.ISysRoleService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.PathMatcher;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yz
 * @since 2025-04-02
 */
@RestController
@RequestMapping("/system/sysRole")
@SpringBootApplication
public class SysRoleController {
    @Autowired
    ISysRoleService sysRoleService;
    @Autowired
    private PathMatcher pathMatcher;

    @PostMapping("/addRole")
    public String addRole(@RequestBody SysRole sysRole) {
        /**相当于 insert into sys_role(role_id,role_name,description) values(?,?)*/
        sysRoleService.save(sysRole);
        return "success";
    }

    @DeleteMapping("/delRole/{roleId}")
    public String delRole(@PathVariable Integer roleId) {
        sysRoleService.removeById(roleId);
        return "success";
    }
    @PutMapping("/updateRole")
    public String updateRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateById(sysRole);
        return "success";
    }
    @GetMapping("/SelectRole/{roleId}")
    public SysRole SelectRole(@PathVariable Integer roleId) {
        SysRole sysRole = sysRoleService.getById(roleId);
        return sysRole;
    }

    /*
    * 新添加一个角色，并将此角色付给超级管理员
    @param sysRole SysRole
    @return string
    * */
    @PostMapping("/add")
    public String testRoleAdd(@RequestBody SysRole sysRole) {
        //写自己的方法
        sysRoleService.testRoleAdd(sysRole);
        return "success";
    }
}


